/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: javase2203 - T8
 * <p>Powered by webrx On 2022-08-09 11:20:32
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T8 {
    final Object a = new Object();
    final Object b = new Object();
    void m1(){
        String t = Thread.currentThread().getName();
        System.out.printf("%s启动%n",t);
        synchronized (b){
            try{
                Thread.sleep(1000);
            }catch(Exception e){
                e.printStackTrace();
            }
            synchronized (a){

            }
        }
        System.out.printf("%s结束%n",t);
    }

    void m2(){
        String t = Thread.currentThread().getName();
        System.out.printf("%s启动%n",t);
        synchronized (a){
            try{
                Thread.sleep(1000);
            }catch(Exception e){
                e.printStackTrace();
            }
            try{
                int c = 6 / 0;

            }catch(Exception e){

            }
            synchronized (b){

            }
        }
        System.out.printf("%s结束%n",t);
    }
    public static void main(String[] args) {
       var t = new T8();
       Thread t1 = new Thread(t::m1,"t1");
       Thread t2 = new Thread(t::m2,"t2");
       t1.start();
       t2.start();
    }
}
